﻿<%@ page title="" language="C#" masterpagefile="~/Site.master" autoeventwireup="true" inherits="DatabasesImport, MainSite" %>
    <asp:Content ClientIDMode="Static" runat="server" ContentPlaceHolderID="BodyContent">
        <div class="contentfull">
            <div class="breadcrumbs">
                <ul id="crumbs">
                    <li><a title="My Account" href="#">My Account</a>
                        <img src="Content/Images/separator.png" alt="&rarr;" class="separator">
                        Databases 			</li>
                </ul>
            </div>

            <div id="showMessages" runat="server" visible="false">
                <div class='success'>
                    <p></p>
                    <li>
                        <span id="mmsg" runat="server"></span>
                    </li>
                    <p></p>
                </div>
            </div>


            <div class="top">
                <div class="innerleft">
                    <h1>
                        <img src="Images/database-icon.png" width="32px" height="32px" alt="Database">
                        <span id="databaseName"><% =GetDatabaseName() %></span>
                        <form id="renameform">
                            <input type="hidden" name="action" value="renamedb" />
                            <input type="hidden" id="hdnUserId" name="hdnUserId" value="<% =GetUserId() %>" />
                            <input type="hidden" name="listid" id="listid" value="<% =GetDatabaseId() %>" />
                            <input type="text" class="inputed" id="dbname" name="dbname" value="<% =GetDatabaseName() %>" />
                            <input type="submit" id="rename-button" value="Rename" />
                        </form>
                        <a id="rename1" title="Click to rename">Rename</a>
                    </h1>
                    <span class="db_value"><% =GetCaseSensitiveCount() %></span>
                    <script type="text/javascript">
                        $(document).ready(function () {
                            var messengerDiv = $("div#showMessages");
                            $("#rename1").click(function (event) {
                                $('#databaseName').hide();
                                $("#rename1").hide();
                                $("#renameform").show().css("display", "inline");
                                return false;
                            });

                            $("#dbname").click(function (event) {
                                return false;
                            });

                            $("#renameform").submit(function (event) {
                                var _data = '<?xml version="1.0" encoding="utf-8"?>' +
                                                '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                                                '<soap:Body>' +
                                                    '<RenameDatabase xmlns="http://tempuri.org/">' +
                                                        ' <dbId>' + $("input#listid").val() + '</dbId>' +
                                                        '<newDBName>' + $("input#dbname").val() + '</newDBName>' +
                                                        ' <loggedInUserId>' + $("input#hdnUserId").val() + '</loggedInUserId>' +
                                                        '</RenameDatabase>' +
                                                    '</soap:Body>' +
                                               '</soap:Envelope>';
                                // alert(_data);
                                $.ajax({
                                    type: "POST",
                                    url: "http://ssica.org/services/CommonService.asmx?op=RenameDatabase",
                                    data: _data,
                                    contentType: "text/xml;charset-uf8",
                                    dataType: "xml",
                                    success: function (msg) {
                                        var result = $("RenameDatabaseResult", msg);
                                        var res = $(result).text();
                                        // alert(res);
                                        if (res != 'error') {
                                            $("#renameform").hide();
                                            $("#databaseName").fadeIn().html(res);
                                            $("#dbname").val(res);
                                            messengerDiv.removeClass().addClass("success");
                                            var showMessage = 'Database has been renamed.';
                                            if (messengerDiv.is(":empty")) {
                                                messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                                            } else {
                                                messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                                            }
                                        } else {
                                            messengerDiv.removeClass().addClass("warning");
                                            var showMessage = 'Database could not be renamed. Certain special characters are not allowed.';
                                            if (messengerDiv.is(":empty")) {
                                                messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                                            } else {
                                                messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                                            }
                                        }

                                    }
                                });
                                return false;
                            });

                            $("body").not("#renameform").click(function (event) {
                                if ($("#renameform").is(':visible')) {
                                    $("#renameform").fadeOut();
                                    $("#databaseName").delay(400).fadeIn();
                                    $("#rename1").delay(400).fadeIn();
                                }
                            });

                        });
                    </script>
                </div>
            </div>
            <div class="content">
                <div class="tabs_box">
                    <ul id="tabs">
                        <li><a class="tabs_off" href="DatabaseSearch.aspx?dbid=<% =GetDatabaseId() %>&mode=Edit">Search</a></li>
                        <li><a class="tabs_off" href="DatabasesAddValue.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Add</a></li>
                        <li><a class="tabs_on" href="#">Import</a></li>
                        <li><a class="tabs_off" href="DatabasesExport.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Export</a></li>
                       <%-- <li><a class="tabs_off" href="DatabasesAutofill.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Autofill</a></li>--%>
                        <li><a class="tabs_off" href="DatabasesClear.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Clear</a></li>
                    </ul>
                </div>
                <fieldset>
                    <div class="import_left">
                        <h2>CSV Import</h2>
                        <form enctype="multipart/form-data" method="post" action="DatabasesAddValue.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">
                            <input type="hidden" name="action" value="uploadlist" />
                            <input type="hidden" name="listid" value="213350" />
                            <input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
                            <label for="csvfile">Save time over manual data entry. Recommended for pre-existing databases.</label>
                            <span for="csvfile" class="lower_comment same">See the template for upoading data by clicking<a target="_blank" href="http://ssics.org\App_Data\UploadFile.csv"> here</a>.</span>
                            <br>
                            <input type="file" name="csvfile" />
                            <br>
                            <input type="submit" value="Import Database" class="black_button blarge" />
                        </form>
                    </div>
                </fieldset>
                <div style="clear: both;"></div>
            </div>

        </div>
    </asp:Content>